<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: SwarmController</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">SwarmController</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/app/controllers/swarm_controller_rb.html">
                app/controllers/swarm_controller.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="ApplicationController.html">
                ApplicationController
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000001">create</a>&nbsp;&nbsp;
      <a href="#M000002">list</a>&nbsp;&nbsp;
      <a href="#M000004">save</a>&nbsp;&nbsp;
      <a href="#M000005">search</a>&nbsp;&nbsp;
      <a href="#M000003">show_one</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000001" class="method-detail">
        <a name="M000001"></a>

        <div class="method-heading">
          <a href="#M000001" class="method-signature">
          <span class="method-name">create</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000001-source">
<pre>
   <span class="ruby-comment cmt"># File app/controllers/swarm_controller.rb, line 3</span>
3:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>
4:  <span class="ruby-ivar">@cl</span>=<span class="ruby-constant">Catelog</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>,<span class="ruby-identifier">:order=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;id asc&quot;</span>).<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>[<span class="ruby-identifier">c</span>.<span class="ruby-identifier">title</span>,<span class="ruby-identifier">c</span>.<span class="ruby-identifier">id</span>]}
5:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000002" class="method-detail">
        <a name="M000002"></a>

        <div class="method-heading">
          <a href="#M000002" class="method-signature">
          <span class="method-name">list</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000002-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/swarm_controller.rb, line 7</span>
 7:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">list</span>
 8:   <span class="ruby-ivar">@catelogs</span>=<span class="ruby-constant">Catelog</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>)
 9:   <span class="ruby-keyword kw">if</span>(<span class="ruby-operator">!</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>].<span class="ruby-identifier">nil?</span>)<span class="ruby-keyword kw">then</span> <span class="ruby-identifier">condition</span>=<span class="ruby-value str">&quot;catelog_id = &quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>] <span class="ruby-keyword kw">end</span>
10:   <span class="ruby-ivar">@result_pages</span>,<span class="ruby-ivar">@swarm</span>=<span class="ruby-identifier">paginate</span>(<span class="ruby-identifier">:swarms</span>,<span class="ruby-identifier">:order=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;creation_time&quot;</span>,<span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">condition</span>,<span class="ruby-identifier">:per_page=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">2</span>)
11:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">save</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/swarm_controller.rb, line 18</span>
18:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save</span>
19:   <span class="ruby-identifier">require</span> <span class="ruby-value str">'digest/md5'</span>
20:   <span class="ruby-identifier">t</span>=<span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
21:   <span class="ruby-identifier">new_url</span>=(<span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">MD5</span>).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">t</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-identifier">session</span>.<span class="ruby-identifier">session_id</span>.<span class="ruby-identifier">to_s</span>).<span class="ruby-identifier">to_s</span>
22: <span class="ruby-identifier">pic_url</span>=(<span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">MD5</span>).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">t</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">'pic_url'</span><span class="ruby-operator">+</span><span class="ruby-identifier">session</span>.<span class="ruby-identifier">session_id</span>.<span class="ruby-identifier">to_s</span>).<span class="ruby-identifier">to_s</span>
23:   <span class="ruby-constant">Swarm</span>.<span class="ruby-identifier">save</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:swarm</span>],<span class="ruby-identifier">new_url</span>,<span class="ruby-identifier">pic_url</span>)
24:   <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>]=<span class="ruby-value str">&quot;you have created a swarm successly!&quot;</span>
25:   <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:controller=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;swarm&quot;</span>,<span class="ruby-identifier">:action=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;show_one&quot;</span>,<span class="ruby-identifier">:id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">new_url</span>
26:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">search</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/swarm_controller.rb, line 28</span>
28:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">search</span>
29:   <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:biaozhun</span>]<span class="ruby-operator">==</span><span class="ruby-value str">&quot;content&quot;</span>)
30:   <span class="ruby-ivar">@result_pages</span>,<span class="ruby-ivar">@result_search</span>=<span class="ruby-identifier">paginate</span>(<span class="ruby-identifier">:swarms</span>,<span class="ruby-identifier">:order=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;id&quot;</span>,<span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span>[<span class="ruby-value str">&quot;title like ? or description like ?&quot;</span>,<span class="ruby-value str">&quot;%&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">:content_search</span>]<span class="ruby-operator">+</span><span class="ruby-value str">&quot;%&quot;</span>,<span class="ruby-value str">&quot;%&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">:content_search</span>]<span class="ruby-operator">+</span><span class="ruby-value str">&quot;%&quot;</span>])
31:   <span class="ruby-keyword kw">end</span>
32:   <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:biaozhun</span>]<span class="ruby-operator">==</span><span class="ruby-value str">&quot;tag&quot;</span>)
33:   <span class="ruby-ivar">@result_pages</span>,<span class="ruby-ivar">@result_search</span>=<span class="ruby-identifier">paginate</span>(<span class="ruby-identifier">:swarms</span>,<span class="ruby-identifier">:order=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;id&quot;</span>,<span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span>[<span class="ruby-value str">&quot;tags like ?&quot;</span>,<span class="ruby-value str">&quot;%&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">:content_search</span>]<span class="ruby-operator">+</span><span class="ruby-value str">&quot;%&quot;</span>])
34:   <span class="ruby-keyword kw">end</span>
35:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="#M000003" class="method-signature">
          <span class="method-name">show_one</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000003-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/swarm_controller.rb, line 13</span>
13:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">show_one</span>
14:   
15:   <span class="ruby-ivar">@swarm</span>=<span class="ruby-constant">Swarm</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>,<span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;url = '&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]<span class="ruby-operator">+</span><span class="ruby-value str">&quot;'&quot;</span>);
16:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>